package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.itheima.dao.BookDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class JdbcConfig {
    //基本类型
    @Value("com.mysql.jdbc.Driver")
    private String driver;
    @Value("jdbc:mysql://localhost:3306/mybatis")
    private String url;
    @Value("root")
    private String username;
    @Value("root")
    private String password;

    //获得要管理的对象
    @Bean//第三方bean申明
    public DataSource dataSource(BookDao bookDao){//引用类型
        System.out.println(bookDao);
        DruidDataSource druidDataSource  = new DruidDataSource();
        druidDataSource.setDriverClassName(driver);
        druidDataSource.setUrl(url);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
